<template>
    <scroll ref="leftSlider">
      <div>
        <ul class="menu-box">
          <li class="menu-item" ref="menuItem"
              v-for="(item, index) in food"
              @click="change(index)"
              :class="{'active': (cartCurrentIndex === index)}">{{item.name}}
          <div class="num" v-show="item.count>0">{{item.count}}</div>
          </li>
        </ul>
      </div>
    </scroll>
</template>

<script>
    import Scroll from "../../../components/scroll/scroll";

    export default {
      components: {Scroll},
      name: "left-slider",
      props: {
        cartCurrentIndex: {
          type: Number,
          default: 0
        },
        food: {
          type: Array,
          default: null
        }
      },
      data () {
        return {
          list: []
        }
      },
      created () {
      },
      mounted () {
      },
      methods: {
        change (index) {
          this.currentIndex = index
          this.$emit('scrollTo', index)
        }
      },
      computed: {
        // totalCount () {
        //   let totalcounts = []
        //   this.food.forEach((food) => {
        //     let obj = {}
        //     let num = 0
        //     food.foods.forEach((item) => {
        //       if (item.count) {
        //         num += item.count
        //       }
        //     })
        //     obj = {
        //       "name": food.name,
        //       "num": num
        //     }
        //     totalcounts.push(obj)
        //   })
        //   this.list = totalcounts
        //   return totalcounts
        // }
      }
    }
</script>

<style scoped>
  .menu-box{
    padding-bottom: 90px;/*rem*/
  }
  .menu-box .menu-item{
    position: relative;
    font-size: 24px;/*px*/
    color: #6d6d6d;
    height: 100px;/*rem*/
    line-height: 100px;/*rem*/
    text-align: center;
    border-bottom: 1px solid #f0f0f0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .menu-box .active{
    color: #333333;
    background-color: #ffffff;
  }
  .menu-box .num{
    position: absolute;
    top:0px;/*rem*/
    right:0px;/*rem*/
    line-height: 1;/*rem*/
    background-image: linear-gradient(-90deg,#ff7416,#ff3c15 98%);
    border-radius: 50%;
    padding: 5px 10px;/*rem*/
    color: #ffffff;
    font-size: 14px;/*rem*/
  }
</style>
